<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="计划月份" >
        <el-date-picker
          v-model="queryParams.planMonth"
          class="datawidth"
          type="month"
          size="small"
          format="yyyy-MM"
          value-format="yyyy-MM"
          @change="search"
          placeholder="选择月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划类型" >
        <el-select
           class="datawidth"
          v-model="queryParams.planType"
          placeholder="请选择"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" >
        <el-select
         class="datawidth"
          v-model="queryParams.auditSteps"
          placeholder="请选择"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in jhztList"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button  size="mini" type="success" icon="el-icon-plus" @click="newAdd">新增</el-button>
        <el-button  type="primary" icon="el-icon-search" size="mini" @click="search" style="margin-left: 10px">搜索</el-button>
        <el-button type="primary" icon="el-icon-tickets" size="mini" @click="feiyong">费用明细</el-button>
      </el-form-item>
    </el-form>
<!-- <div class="box" style="width:100%;color: #515a6e;font-weight: bold;font-size:13px;z-index=10;" v-if="false">
  <div style="height:80px;border-right:1px solid #ccc;float:left; position:relative;margin-right:10px;padding-right:10px" v-for="(item,index) in price" :key="index">
    {{item.costProName}}
    <div style="margin-top:10px;margin-bottom:20px">已使用/总费用/剩余:</div>
    <span style="color:">{{item.remaining}}</span> /
    <span style="color:">{{item.sun}}</span> /
    <span>{{item.use}}</span>
      </div>
   </div> -->

    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column width="200" align="center" label="审核状态"  property="auditSteps" :show-overflow-tooltip="true"  >
        <template slot-scope="scope" style="text-align: center">
          <div style="background:#78BF34  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='0'" >未提交</div>
          <div style="background:#9E71DC  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='1'">战线审核</div>
          <div style="background:#DEA11E  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='2'">经营科审核</div>
          <div style="background:#78BF34  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='3'" >利库审核</div>
          <div style="background:#9E71DC  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='4'">经营科长审核</div>
          <div style="background:#DEA11E  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='5'">驳回</div>
          <div style="background:#78BF34  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='6'" >通过</div>
          <div style="background:#9E71DC  ;color: white;padding-left:10px;padding-right:10px;display: inline-block" v-show="scope.row.auditSteps=='7'">废单</div>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="需求计划名称"   property="pickName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label=" 资金来源名称"   property="moneySourceName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column  align="center" label="计划月份"   property="planMonth" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="金额/元"  property="totalAmount"  ></el-table-column>
      <el-table-column align="center" label="计划号" property="planNum" :show-overflow-tooltip="true" v-if="false" ></el-table-column>
      <el-table-column
        label="操作"
        width="400"
        align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            icon="el-icon-s-unfold"
            @click="xingqing(scope.row)">详情</el-button>
          <el-button
            size="mini"
            v-show="scope.row.auditSteps=='0' ||scope.row.auditSteps=='5'"
            type="primary"

            icon="el-icon-edit"
            @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button
            size="mini"
            type="primary"

            v-show="scope.row.auditSteps=='0' ||scope.row.auditSteps=='5'"
            icon="el-icon-finished"
            @click="handlesave(scope.$index, scope.row)">提交</el-button>
          <el-button
            size="mini"
            type="danger"

            v-show="scope.row.auditSteps=='0' || scope.row.auditSteps=='5'"
            icon="el-icon-delete"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />
    <price-MX v-if="priceShow" :month="planMonth" ref="sprice"></price-MX>
  </div>
</template>

<script>
  import request from '@/utils/request'
  import priceMX from '@/views/suppliesLLGL/priceMX.vue'
  export default {
    name: "Role",
    components:{
      // xqjhDialog,
      priceMX
    },
    data() {
      return {
        //记录分页数据
        localPage:undefined,
        localSize:undefined,
        planMonth:{},
        xqjhShow:false,
        xqjhStr:{},
        //详情价格展示
        priceShow : false,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],
        //价格数据
        price: [],
        //资金来源
        zjlyList:[
          { value: '1',label: '来源1'},
          { value: '2',label: '来源2'},
        ],
        //计划状态
        jhztList:[
          { value: '0',label: '未提交 '},
          { value: '1',label: '战线审核'},
          { value: '2',label: '经营科审核'},
          { value: '3',label: '利库审核'},
          { value: '4',label: '经营科长审核'},
          { value: '5',label: '驳回'},
          { value: '6',label: '通过'},
          { value: '7',label: '废单'},
        ],
        // 状态数据字典
        statusOptions: [
          { value: '1',label: '月度计划'},
          { value: '2',label: '临时计划'},
        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          planMonth:'',
          planType:'',
          auditSteps:'',
        },
        // 表单参数
        form: {},
      };
    },
    created() {
      var myDate = new Date();
      var yue = myDate.getMonth()+1
      if(yue<9){
        yue = '0'+yue
      }
      this.queryParams.planMonth =  myDate.getFullYear()+'-'+ yue+'';
      console.log('接收-详情页码',this.$route.query)
      this.localSize = this.$route.query.size
      this.localPage = this.$route.query.page
      if(this.localPage!==undefined) {
          this.queryParams.pageNum = this.localPage
      }
      if(this.localSize!==undefined) {
        this.queryParams.pageSize = this.localSize
      }
      this.search()
      // console.log(this.queryParams.planMonth)
      // this.getPrice()
      console.log(this.queryParams)
    },
    methods: {
      feiyong:function(){
        this.priceShow = true
        var obj={
          planMonth:this.queryParams.planMonth
        }
         this.planMonth = obj
         this.$refs.sprice.dialogTableVisible=true
      },
      //复选框监听
      handleSelectionChange:function(val){
        console.log(val)
      },

      //详情价格信息展示
      // priceXQ () {
      //   this.priceShow = true
      //   console.log(456)
      // },
      //新增
      newAdd:function(){
        this.$router.push({path:'/material/xqjhAdd',query:{data:'55555',page:this.localPage,size:this.localSize},});
      },
      //查询
      search:function(){
        this.loading = true
        this.localPage = this.queryParams.pageNum
        this.localSize = this.queryParams.pageSize
        // this.getPrice()
        request({
          url: '/system/demandPlan/list',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          this.total = response.total
          console.log(this.total)
          console.log('111111',this.roleList)
        });
      },
      //表格修改
      handleEdit:function (index,row) {
        console.log(row)
        this.$router.push({path:'/material/xqjhAdd',query:{data:row,page:this.localPage,size:this.localSize}});
      },
      //提交
      handlesave:function(index,row){
        this.$confirm('确认提交?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.saveBtn(row)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          });
        });
      },
      saveBtn:function(row){
        var obj={}
        obj.id = row.id
        obj.auditSteps = 1
        request({
          url: '/system/demandPlan/steps',
          method: 'put',
          data: obj
        }).then(response => {
          if(response.code=='200'){
            this.$message({
              type: 'success',
              message: '提交成功!'
            });
          }
          this.search();
        });
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
         this.shanchu(row)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      shanchu:function(row){
        request({
          url: '/system/demandPlan/' + row.id,
          method: 'delete',
        }).then(response => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.search()
        });
      },

      //详情点击
      xingqing:function (row) {
        console.log(row)
        this.$router.push({path:'/material/xqjhXQ',query:{data:row,page:this.localPage,size:this.localSize}});
      },

    }
  };
</script>
<style lang="scss">
</style>
